{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a674050b-e8a8-4170-b3c4-262fb8694b4d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w= [-0.20416667  0.17083333] b= [0.69583333]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "x=np.array([[2,3],[3,4],[6,5],[4,4],[3,2],[4,7],[5,4],[4,3],[7,5],[3,3],[4,4],[5,2]])\n",
    "y=np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])\n",
    "model=LinearRegression()\n",
    "model.fit(x,y)\n",
    "print(\"w=\",model.coef_[0],\"b=\",model.intercept_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c85302fb-27ab-492b-856c-68c27039ed23",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测准确率为: 0.5270138888888887\n"
     ]
    }
   ],
   "source": [
    "x_test=np.array([[3,5],[2,4],[5,6],[3,6],[3,3],[4,5],[4,2],[5,5],[6,7],[5,3],[6,4],[6,6]])\n",
    "y_test=np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])\n",
    "r2=model.score(x_test,y_test)\n",
    "print(\"预测准确率为:\",r2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6b2b499e-4ff1-4012-812c-056c82f96473",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "新样本的预测标签为: [1.27916667]\n"
     ]
    }
   ],
   "source": [
    "a=model.predict([[3,7]])\n",
    "print(\"新样本的预测标签为:\",a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "450c2923-94a0-4290-90eb-97c64fc34fa3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
